package com.design.mall;

import com.design.mall.impl.CashDiscount;
import com.design.mall.impl.CashNormal;
import com.design.mall.impl.CashRebate;

import java.util.HashMap;
import java.util.Map;

/**
 * 结合工厂类
 *
 * @author by liuxin
 * @version 0.1
 */
public class CashContext2 {
    CashRegister cashRegister;
    String message = "";

    public CashContext2(int type) {
        switch (type) {
            case 1 -> {
                cashRegister = new CashNormal();
                this.message += "正常收费";
            }
            case 2 -> {
                cashRegister = new CashRebate(300, 100);
                this.message += "满300返100";
            }
            case 3 -> {
                cashRegister = new CashDiscount(0.8);
                this.message += "打8折";
            }
            default -> {
                System.out.println("请输入1/2/3");
                this.message = "输入错误";
            }
        }
    }

    public Map<String, Object> pay(double money) {
        Map<String, Object> cash = new HashMap<>(4);
        cash.put("money", cashRegister.acceptCash(money));
        cash.put("message", message);
        return cash;
    }
}
